package com.bsh.api;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.bsh.service.AccountService;
import com.bsh.service.SmsService;
import com.bsh.service.UserService;
import com.bsh.service.UserVerifyService;
/**
 * 验证相关API
 * 
 * @author gsh
 * @since 0.0.1
 * 
 */
@Controller
public class EtlController {
	private static Logger log = LoggerFactory.getLogger(EtlController.class);
	@Autowired
	HttpServletRequest request;
	@Autowired
	HttpServletResponse response;
	@Autowired
	HttpSession session;
	@Autowired
	UserService servUser;
	@Autowired
	AccountService accountServ;
	@Autowired
	UserVerifyService userVerifyService;
	@Autowired
	SmsService servSms;
	@Autowired
	private UserService userService;
	@Autowired
	private AccountService accService;

	/**
	 * 测试
	 * 
	 * @param loginName
	 * @param password
	 * @return
	 * @throws IOException 
	 * @throws NoSuchAlgorithmException 
	 * @throws Exception
	 */
	@RequestMapping(value = "/api/etl")
	@ResponseBody
	public ModelAndView test() throws IOException, NoSuchAlgorithmException{
		 
		/*
		Integer pageIndex = 1; 
		Integer pageSize = 60000;
		UserListQryDto dto = new UserListQryDto();
		
		Pager pager = new Pager(pageIndex, pageSize);
		List<Map<String, Object>> list = userService.getPage(pager,dto);
//		System.out.println( list.size() );
		for (int i = 0; i < list.size(); i++) {
			Map Mapv = list.get(i);
			String password = (String) Mapv.get("password");
			Integer id = (Integer) Mapv.get("id");
//			DesUtils desN=new DesUtils();
//			String newpayPassword = desN.encrypt(password); 
//			response.getWriter().println( newpayPassword+" | "+"<br/>" );
			
			boolean res = userService.etlChangPassword(id, password, password,"etl");
			
			Account accInfo = accService.getAccountByUserId(id);
			Account accInfoNew = new Account();
			accInfoNew.setUserid(accInfo.getUserid());
			accInfoNew.setId(accInfo.getId());
			String payPassword = accInfo.getPayPassword();
			DesUtils desN=new DesUtils();
			String newpayPassword = desN.encrypt(payPassword);
			accInfoNew.setPayPassword(newpayPassword);
			Integer accRes = accService.editAccountPassword(accInfoNew);
						
			response.getWriter().println( id+" | "+ res +" >acc> "+accRes+"<br/>" );
		}
//		String resultMd5=MD5.getMD5("test".getBytes()); //098f6bcd4621d373cade4e832627b4f6
	 
		response.getWriter().println(list.size() + "====================" );
		 
//		*/ 
		return null;
	}

	
	
	
}
